import { API, API1, API3, BASE_URL, FONT_API, SEARCH_API, BASE_URL_G, PREV_API, HOT_API } from 'js/config'
import $http from 'js/request'

// 注册
export const apiRegister = (mobile, password, smsCode, type = '1') => {
    return $http.post(`${API}user/register`, { mobile, password, smsCode, type })
}

// 注册用户协议
export const apiAgreement = () => {
    return $http.post(`${API}user/agreement`, {})
}

// 判断用户是否已存在
export const apiExistence = (userName) => {
    return $http.post(`${API}user/userExistInfo`, { userName })
}

// 登录
export const apiLogin = (userName, password, deviceNo, deviceType = 'PC') => {
    return $http.post(`${API}user/login`, { userName, password, deviceNo, deviceType })
}

// 获取验证码
export const apiMsgCode = (username) => {
    return $http.post(`${API}msgSet/sendMsg`, { mobile: username })
}

// 修改密码
export const apiUpdatePwd = (accessToken, pwd, newPwd) => {
    return $http.post(`${API}user/alertPassWord`, { accessToken: accessToken, password: pwd, newPassword: newPwd })
}

// 找回密码
export const apiBackPwd = (mobile, newPassword, smsCode) => {
    return $http.post(`${API}user/getBackPassWord`, { mobile, newPassword, smsCode })
}

// 请求商品详情
export const apiGoodsDetail = (id, accessToken) => {
    return $http.post(`${API}goods/queryGoodsById`, { accessToken: accessToken, goodsId: id })
}

// 猜你喜欢接口
export const apiGuessYouLike = (params) => {
    return $http.post(`${API}goods/guessYouLikeGoods`, params)
}

export const apiGoodsDraft = (goodsId, token) => {
    return $http.post(`${API}draft/getGoodsDraft`, { goodsId: goodsId, accessToken: token })
    // return $http.post(`${PREV_API}draft/getGoodsDraft`, { goodsId: goodsId, accessToken: token })
}

// 商品众筹规则
export const apiGoodsDetailRule = (id) => {
    return $http.post(`${API}goods/queryGoodsRulesById`, { goodsId: id })
}

// 首页行业
export const apiTrade = () => {
        return $http.post(`${API}trade/queryTradeInfo`, {})
    }
    //首页频道
export const apiChannelFloor = (id, token) => {
        if (token) {
            return $http.post(`${API}channelfloor/selectChannelsFloorAll`, { chId: id, accessToken: token })
        } else {
            return $http.post(`${API}channelfloor/selectChannelsFloorAll`, { chId: id })
        }

    }
    // 首页导航bannerBar
export const apiIndexNav = (tradeId) => {
    return $http.post(`${API}title/queryTitleInfo`, { tradeId: tradeId })
}

// 首页banner轮播图
export const apiBanner = id => {
    return $http.post(`${API}banner/queryBannerByChannelId`, { chId: id, type: 'Pc' })
}

// 首页导航跳转
export const apiChannel = (url, id) => {
    return $http.post(`${API}`, { chId: id })
}

// 热搜
export const apiHotSearch = () => {
        return $http.post(`${BASE_URL}api/web/v2/index`)
    }
    // 首页左侧导航LeftFloat
export const apiLeftNav = (tradeId) => {
    return $http.post(`${BASE_URL}api/web/v2/trade/tradeList`, { tradeId: tradeId })
}

// 首页楼层indexFloor
export const apiIndexFloor = (tradeId, token) => {
    if (token) {
        return $http.post(`${API}goodsfloor/selectGoodsFloorAll`, { tradeId: tradeId, accessToken: token })
    } else {
        return $http.post(`${API}goodsfloor/selectGoodsFloorAll`, { tradeId: tradeId })
    }
}

// 首页分类导航
export const apiIndexClassify = () => {
    return $http.post(`${API}goodsClass/queryGoodsClassAll`)
}

// 根据楼层，banner类型为goodsList时，调用接口，
export const queryListByGoodsIds = (goodsIdList) => {
    return $http.post(`${API}goods/queryListByGoodsIds`, { goodsIdList })
}

// 根据用户id获取购物车全部商品
export const apiCartAll = (accessToken, currentPage = 1, showCount = 100) => {
    return $http.post(`${API}goodsCart/selectGoodsCartAll`, { accessToken, currentPage, showCount })
}

// 购物车数量修改
export const apiCartCount = (accessToken, goodsCartList) => {
    return $http.post(`${API}goodsCart/editGoodsCartCount`, { accessToken, ...goodsCartList })
}

// 删除购物车商品
export const apiDeleteCartGood = (accessToken, goodsIds, goodsCartIds, storeIds) => {
    return $http.post(`${API}goodsCart/deleteGoodsCart`, { accessToken, goodsIds, goodsCartIds, storeIds })
}

// 获取购物车商品总数量
export const apiCartGoodCount = accessToken => {
    return $http.post(`${API}goodsCart/getGoodsCountInGcart`, { accessToken })
}

// 购物车结算
export const apiBalanceStatus = (accessToken, goodsCartIds) => {
    return $http.post(`${API}goodsCart/balanceStatus`, { accessToken, goodsCartIds })
}

// 当前用户所有地址列表
export const apiAddressAll = (accessToken, currentPage, showCount) => {
    return $http.post(`${API}address/selectAddressAll`, { accessToken, currentPage, showCount })
}

// 修改地址
export const apiEditAddress = (accessToken, address) => {
    return $http.post(`${API}address/editAddress`, { accessToken, ...address })
}

// 删除地址
export const apiDeleteAddress = (accessToken, id) => {
    return $http.post(`${API}address/deleteAddress`, { accessToken, id })
}

// 新增地址
export const apiAddAddress = (accessToken, address) => {
    return $http.post(`${API}address/addAddress`, { accessToken, ...address })
}

// 修改默认地址
export const apiEditDefaultAddress = (accessToken, id) => {
    return $http.post(`${API}address/editDefault`, { accessToken, id })
}

// 根据主键ID获取单条地址信息
export const apiSelectAddressById = id => {
    return $http.post(`${API}address/selectAddressById`, { id })
}

// 获取区域
export const apiAreaAll = () => {
    return $http.post(`${API}area/selectAreaAll`, {})
}

// 获取当前所有订单信息
export const apiOrderAll = (accessToken, currentPage, orderStatus, vagueSearchVal, showCount = 10, orderInfo = {}) => {
    return $http.post(`${API}orderForm/selectOrderFormAll`, { accessToken, currentPage, orderStatus, vagueSearchVal, showCount, ...orderInfo })
}

// 获取当前所有退款订单信息
export const apiOrderRefundAll = (accessToken, currentPage, status, beginTime, endTime, showCount = 10, waitDelivorderType = '21', orderInfo = {}) => {
    return $http.post(`${API}orderForm/selectOrderFormAll`, { accessToken, currentPage, status, beginTime, endTime, showCount, waitDelivorderType, ...orderInfo })
}

// 根据订单ID获取订单信息
export const apiOrderByToken = (accessToken, cartStatus, receiverAddrId) => {
    return $http.post(`${API}goodsCart/selectBalanceAll`, { accessToken, cartStatus, receiverAddrId })
}

// 通过订单ids，获取订单信息
export const apiOrderByIds = (accessToken, ids) => {
    return $http.post(`${API}orderForm/selectOrderFormByIds`, { accessToken, ids })
}

// 修改订单状态
export const apiEditOrderStatus = (accessToken, id, orderStatus, orderNo = null) => {
    return $http.post(`${API}orderForm/editOrderFormOrderStatus`, { accessToken, id, orderStatus, orderNo })
}

// 根据订单id，修改订单留言数据
export const apiEditOrderMsg = (accessToken, paramList) => {
    return $http.post(`${API}orderForm/editOrderFormMessage`, { accessToken, paramList })
}

// 删除订单
export const apiDeleteOrder = (ids) => {
    return $http.post(`${API}orderForm/deleteOrderForm`, { ids })
}

// 新增订单
export const apiAddOrder = (accessToken, orderInfo) => {
    return $http.post(`${API}orderForm/addOrderForm`, { accessToken, ...orderInfo })
}

// 取消订单/退款原因选择
export const apiSelectdictionaryDataByTypeId = (typeId = '1') => {
    return $http.post(`${API}dictionaryData/selectdictionaryDataByTypeId`, { typeId })
}

// 订单详情，订单退款
export const apiRefundOrderFormById = (accessToken, orderFormId, userApplyReason, userApplyExplain, userApplyImg, refundType, goodsCartId, type, refund) => {
    return $http.post(`${API}orderForm/refundOrderFormById`, { accessToken, orderFormId, userApplyReason, userApplyExplain, userApplyImg, refundType, goodsCartId, type, refund })
}

// 订单详情，获取订单退款详情
export const apiRefundOrderInfo = (accessToken, id, goodsCartId) => {
    return $http.post(`${API3}orderForm/getOrderFormGoodsInfoById`, { accessToken, id, goodsCartId })
}

// 订单详情，退货退款
export const apiRefundOrderGoods = (accessToken, orderId, userApplyReason, userApplyExplain, userApplyImg, refund, goodsCartId, type) => {
    return $http.post(`${API1}orderForm/returnOrderFormById`, { accessToken, orderId, userApplyReason, userApplyExplain, userApplyImg, refund, goodsCartId, type })
}

// 订单详情，获取协商历史
export const apiRefundHistory = (accessToken, orderId, goodsId) => {
    return $http.post(`${API3}orderForm/getOrderFormGoodsChatById`, { accessToken, orderId, goodsId })
}

// 订单详情，换货
export const apiRefundGoods = (params) => {
    return $http.post(`${API3}orderForm/exchangeOrderFormById`, params)
}

// 订单详情，查询订单退款信息
export const apiRefundOrderForStatusmById = (accessToken, orderformId, refundType) => {
    return $http.post(`${API}orderForm/refundOrderFormStatusById`, { accessToken, orderformId, refundType })
}

// 订单支付结果修改
export const apiOrderPayResult = (accessToken, id, payment_id, pay_msg) => {
    return $http.post(`${API}orderForm/orderPaymentResult`, { accessToken, id, payment_id, pay_msg })
}

// 订单中心，修改订单地址
export const apiEditOrderAddress = (accessToken, paramList) => {
    return $http.post(`${API}orderForm/editOrderFormByIds`, { accessToken, paramList })
}

// 查询各订单状态下的订单数量
export const apiOrderStatusCount = accessToken => {
    return $http.post(`${API}orderForm/selectOrderFormCount`, { accessToken })
}

// 获取邮费接口
export const apiGetShipPrice = (receiver_addr_id, goodsList) => {
    return $http.post(`${API}goodsCart/getshipPrice`, { receiver_addr_id, goodsList })
}

// 订单物流信息接口
export const apiGetExpress = (shipCode, orderId) => {
    return $http.post(`${API}order/getExpress`, { shipCode, orderId })
}

// 新增订单评价接口
export const apiAddEvaluate = (accessToken, orderformId, evaluGoodsInfo) => {
    return $http.post(`${API}evaluate/addEvaluate`, { accessToken, orderformId, evaluGoodsInfo })
}

// 商品详情页的商家基本信息, 订单详情页根据商家ID获取商家详情
export const apiStoreInfo = (storeId, accessToken) => {
    return $http.post(`${API}store/queryStoreById`, { storeId, accessToken })
}

// 商品详情页的热门商品列表
export const apiHotGoods = (goodsId) => {
    return $http.post(`${API}goods/hotGoods`, { goodsId: goodsId })
}

// 新商品详情页的热门商品列表
export const apiHotGoodsNew = () => {
    return $http.post(`${HOT_API}goods/queryBoutiqueGoods`, {})
}

// 搜索商品列表
export const apiSerachGoods = (params = {}, showCount = 20) => {
    return $http.post(`${SEARCH_API}lucene/searchByLucene`, { ...params, showCount })
}

// 我的足迹--查询
export const apiFootPrint = (token, currentPage, showCount) => {
    return $http.post(`${API}footPrint/findFootPrint`, { accessToken: token, currentPage: currentPage, showCount: showCount })
}

// 新增足迹
export const apiAddFootPrint = (goodsId, storeId, accessToken) => {
    return $http.post(`${API}footPrint/addFootPrint`, { accessToken, goodsId, storeId })
}

// 商品收藏
export const apiSelectFavoriteAll = (token, currentPage, showCount) => {
    return $http.post(`${API}favorite/selectFavoriteAll`, { accessToken: token, currentPage: currentPage, showCount: showCount })
}

// 店铺收藏
export const apiSelectFavoriteStoreAll = (token, currentPage, showCount) => {
    return $http.post(`${API}favorite/selectFavoriteStoreAll`, { accessToken: token, currentPage: currentPage, showCount: showCount })
}

// 商品详情页的收藏商品
export const apiFavoriteGoods = (accessToken, goodsId, favouriteSource = '0') => {
    return $http.post(`${API}favorite/addFavoriteGoods`, { accessToken, favoriteGoodsList: [{ favouriteSource, goodsId }] })
}

// 商品详情页的收藏店铺
export const apiFavoriteStore = (storeId, accessToken) => {
    return $http.post(`${API}favorite/addFavoriteStore`, { accessToken, storeId: storeId })
}

// 普通商品分类菜单
export const apiGoodsClassAll = () => {
    return $http.post(`${API}goodsClass/queryGoodsClassAll`)
}

// 商品成交记录
export const apiBargainOrderForm = (goodsId, currentPage, showCount) => {
    return $http.post(`${API}orderForm/bargainOrderForm`, { goodsId: goodsId, currentPage: currentPage, showCount: showCount })
}

// 商品评价信息
export const apiCommentOrderForm = (goodsId, evaluateBuyerVal, currentPage, showCount) => {
    return $http.post(`${API}evaluate/selectEvaluateAllByGoodsId`, { goodsId: goodsId, evaluateBuyerVal: evaluateBuyerVal, currentPage: currentPage, showCount: showCount })
}

// 加入购物车
export const apiAddGoodsCart = (data) => {
    return $http.post(`${API}goodsCart/addGoodsCart`, data)
}

// 立即购买
export const apiImmediatelyBuy = (data) => {
    return $http.post(`${API}goodsCart/immediatelyBuy`, data)
}

// 采购商/供应商申请信息
export const apiApplyRoleInfo = accessToken => {
    return $http.post(`${API}valueAdd/applyRoleInfo`, { accessToken })
}

// 采购商/供应商申请
export const apiApplyRole = (accessToken, oInfo) => {
    return $http.post(`${API}valueAdd/applyRole`, { accessToken, ...oInfo })
}
// 采购商/供应商申请信息更新
export const apiCreateUpdateIndex = (searchType, storeId) => {
    return $http.post(`${SEARCH_API}lucene/createUpdateIndex`, { searchType, storeId })
}

// 获得 采购商/供应商 申请费用
export const apiApplyRoleFee = (accessToken, type) => {
    return $http.post(`${API}valueAdd/applyRoleFee`, { accessToken, type })
}

// 获得 采购商/供应商 支付参数
export const apiApplyPay = (accessToken, orderId, feeId, returnUrl) => {
    return $http.post(`${API}valueAdd/applyRoleAliPay`, { accessToken, orderId, feeId, returnUrl })
}

// 新增订单
export const apiAddOrders = (params) => {
    return $http.post(`${API}orderForm/addOrderForm`, params)
}

// 获取邮费接口
export const apiShipPrice = (id, list) => {
    return $http.post(`${API}goodsCart/getshipPrice`, { receiver_addr_id: id, goodsList: list })
}

// 个人信息修改
export const apiPersonalInfoEdit = (accessToken, userinfo) => {
    return $http.post(`${API}valueAdd/editPersonalInfor`, { accessToken, ...userinfo })
}

// 个人信息查看
export const apiPersonalInfo = accessToken => {
    return $http.post(`${API}valueAdd/selectPersonalInfor`, { accessToken })
}

// 店铺信息导航信息
export const apiShopNav = (storeId, decorationType = 'PC') => {
    return $http.post(`${API}visualNavigation/selectVisualNavigationAll`, { storeId, decorationType })
}

// 店铺信息楼层信息
export const apiShopFloor = (storeId, decorationType = 'PC') => {
    return $http.post(`${API}visualFloor/selectVisualFloorAll`, { storeId, decorationType })
}

// 底部导航信息
export const apiQueryFinallyInfo = () => {
    return $http.post(`${API}title/queryFinallyInfo`, {})
}

// 支付
export const apiPayment = (accessToken, id, txCode, paymentWay) => {
    return $http.post(`${API}pay/cpcnpay`, { accessToken, id, txCode, paymentWay }, false)
}

// 获取农商行的支付信息
export const apiRCBPayment = (accessToken, id) => {
    return $http.post(`${API}order/rcbBankPay`, { accessToken, id })
}

// 增值服务 支付
export const apiIncrementPay = (accessToken, id, feeId, txCode, paymentWay, status = '') => {
    return $http.post(`${API}pay/incrementPay`, { accessToken, id, feeId, txCode, paymentWay, status }, false)
}

// 增值服务升级协议
export const apiEnterArgeement = () => {
    return $http.post(`${API}valueAdd/showAgreement`, {})
}

// 判断用户角色
export const apiUserRole = accessToken => {
    return $http.post(`${API}user/userRole`, { accessToken })
}

// 获取商家档案（商家店铺页面）
export const apiStoreArchives = (storeId, accessToken) => {
    return $http.post(`${API}store/queryStoreArchives`, { storeId: storeId, accessToken: accessToken })
}

// 商铺内商品搜索
export const apiStoreNavigationAll = (params) => {
    return $http.post(`${API}visualNavigation/selectStoreNavigationAll`, params)
}

// 聊天 根据店铺id获取客服信息
export const apiQueryCustomerByStoreId = (storeId, mobile) => {
    return $http.post(`${API}store/queryCustomerByStoreId`, { storeId, mobile })
}
//聊天 通过手机号和客户聊天
export const apiQueryCustomerByPhoneNumber = (mobile) => {
    return $http.post(`${API}store/queryCustomerByMobile`, { mobile })
}
// 聊天 发送消息
export const apiChatSendMsg = params => {
    return $http.post(`${API}chat/sendMessage`, {...params })
}

// 商品详情中获取邮费接口
export const apiGoodsDetailShipPrice = (params) => {
    return $http.post(`${API}goodsDetail/getgoodsDetailshipPrice`, params)
}

// 获取贷款机构
export const apiGetAllInstitutionNames = () => {
    return $http.get(`${BASE_URL_G}institution/v1/getAllInstitutionNames`, '')
}

// 判断是否注册为供应链
export const apiIsExist = (phone) => {
    return $http.post(`${BASE_URL_G}system/v1/isExist`, { user_phone: phone })
}

// 注册为供应链
export const apiFinceRegist = (data) => {
    return $http.post(`${BASE_URL_G}system/v1/regist`, data)
}

// 贷款提交接口
export const apiLoanApply = (data) => {
    return $http.post(`${BASE_URL_G}loanManage/v1/loanApply`, data)
}

// 重置订单
export const apiOrderFina = (data) => {
    return $http.post(`${API}orderForm/editOfFina`, data)
}

// 新首页分类导航
export const apiIndexClassifyNew = () => {
    return $http.post(`${BASE_URL}api/app/v1/showClass/showViewClass `, { "showType":"Pc" })
}

// 获取贷款软文的接口
export const apiGetArticle = (data) => {
    return $http.get(`${BASE_URL_G}article/v1/getArticle?type=attention`, '')
}

export const apiApplyOrderFormPay = (params) => {
    return $http.post(`${API}valueAdd/applyWebOrderFormPay`, params, true)
}

// 增值服务 (原生) 支付
export const apiApplyIncrementPay = (accessToken, id, feeId, type, status = '') => {
    return $http.post(`${API}valueAdd/applyWebRolePay`, { accessToken, id, feeId, type, status })
}

//视频接口
export const queryVideoPath = (showType, chId, tradeId) => {
    return $http.post(`${API}channel/queryVideoPath`, { showType: 'Pc', chId: '0', tradeId: '2' })
}